package com.longge;

public class RemoveDuplicates {

    int len = 0;

    public int removeDuplicates(int[] nums) {

        len = nums.length;
        int pre = Integer.MIN_VALUE,count = 0;

        for (int i = 0; i < len; i++) {
            if (pre==nums[i]){
                count++;
                if (count>2){
                    copyArr(i,nums);
                    count--;
                    len--;
                    i--;
                }
            }else {
                pre=nums[i];
                count = 1;
            }
        }
        return len;

    }

    private void copyArr(int i, int[] nums) {
        boolean flag = false;

        for (int j = 0; j < nums.length; j++) {
            if (j==i||flag){
                flag = true;
            }
            if (!flag){
                nums[j]=nums[j];
            }else {
                if (j==nums.length-1){
                    nums[j] = 0;
                }else {
                    nums[j]=nums[j+1];
                }
            }

        }
    }

    public static void main(String[] args) {
        new RemoveDuplicates().removeDuplicates(new int[]{0,0,1,1,1,1,2,3,3});
    }


}
